CSharpTest.Net
ReadOnly Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace > BPlusTreeOptions<TKey,TValue> Class : ReadOnly Property

Glossary Item Box

Sets the BTree into a read-only mode (only supported when opening an existing file)

Syntax

Visual Basic (Declaration) 
Public Property ReadOnly As Boolean
C# 
public bool ReadOnly {get; set;}

Example

BPlusTree/BPlusTree.Test/TestMultiInstance.cs

C#Copy Code
using (var tempFile = new TempFile())
{
    var options = new BPlusTree<int, string>.OptionsV2(new PrimitiveSerializer(), new PrimitiveSerializer())
                      {
                          CreateFile = CreatePolicy.Always,
                          FileName = tempFile.TempPath,
                      }.CalcBTreeOrder(4, 10);

    var readcopy = options.Clone();
    readcopy.CreateFile = CreatePolicy.Never;
    readcopy.ReadOnly = true;

    using (var tree = new BPlusTree<int, string>(options))
    {
        using (var copy = new BPlusTree<int, string>(readcopy))
        {
            copy.EnableCount();
            Assert.AreEqual(0, copy.Count);
        }

        //insert some data...
        tree.AddRange(MakeValues(0, 100));

        using (var copy = new BPlusTree<int, string>(readcopy))
        {
            copy.EnableCount();
            Assert.AreEqual(0, copy.Count);
        }
        tree.Commit();

        //insert some data...
        for (int i = 0; i < 100; i++)
            tree.Remove(i);
        tree.AddRange(MakeValues(1000, 1000));

        using (var copy = new BPlusTree<int, string>(readcopy))
        {
            copy.EnableCount();
            Assert.AreEqual(100, copy.Count);
            Assert.AreEqual(0, copy.First().Key);
            Assert.AreEqual(99, copy.Last().Key);
        }

        tree.Commit();

    }
}
VB.NETCopy Code
Using tempFile As var = New TempFile()
    Dim options As var = New BPlusTree(Of Integer, String).OptionsV2(New PrimitiveSerializer(), New PrimitiveSerializer()) With { _
        Key .CreateFile = CreatePolicy.Always, _
        Key .FileName = tempFile.TempPath _
    }.CalcBTreeOrder(4, 10)

    Dim readcopy As var = options.Clone()
    readcopy.CreateFile = CreatePolicy.Never
    readcopy.[ReadOnly] = True

    Using tree As var = New BPlusTree(Of Integer, String)(options)
        Using copy As var = New BPlusTree(Of Integer, String)(readcopy)
            copy.EnableCount()
            Assert.AreEqual(0, copy.Count)
        End Using

        'insert some data...
        tree.AddRange(MakeValues(0, 100))

        Using copy As var = New BPlusTree(Of Integer, String)(readcopy)
            copy.EnableCount()
            Assert.AreEqual(0, copy.Count)
        End Using
        tree.Commit()

        'insert some data...
        Dim i As Integer = 0
        While i < 100
            tree.Remove(i)
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
        tree.AddRange(MakeValues(1000, 1000))

        Using copy As var = New BPlusTree(Of Integer, String)(readcopy)
            copy.EnableCount()
            Assert.AreEqual(100, copy.Count)
            Assert.AreEqual(0, copy.First().Key)
            Assert.AreEqual(99, copy.Last().Key)
        End Using


        tree.Commit()
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys